<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Home</title>
        <link rel='stylesheet' href='../css/reset.css'/>
        <link rel='stylesheet' href='../css/960.css'/>
        <link rel='stylesheet' href='css/style.css'/>
    </head>
    <body>
        <div id ="container" class="container_12">
            
            <div id="banner" class="grid_12">
                    <img src='../img/logo.png'>
            </div><!--end banner wrap-->
            
            <div id="body" class="grid_12">
                <div id="siteBar" class="grid_4">
                    <?php
                        include 'siteBar.php';
                    ?>
                </div><!--end siteBar wrap -->
                <div id="main" class="grid_7">
                    <div class="section">
                        <h2>Danh sách tin tức</h2>
                        <form>
                            <?php
                                require "DB.php";
                                $pagesize = 6;
                                $currentpage = 1;
                                if (isset($_GET["currentpage"]))
                                    $currentpage = $_GET["currentpage"];
                                if (isset($_REQUEST["q"])) 
                                    $q = $_REQUEST["q"]; 
                                $query = "SELECT count(*) as NUMROW FROM NEWS";
                                $result = mysql_query($query);
                                $row = mysql_fetch_array($result);
                                $numrow = $row["NUMROW"];
                                $numpage = ceil($numrow / ($pagesize*1.0));

                                $start = ($currentpage-1) * $pagesize;

                                $self = $_SERVER['PHP_SELF'];
                                $nav = "";
                                $nav.= "<div class='section paginations'> ";
                                for($i = 1; $i <= $numpage; $i ++)
                                {
                                        if ($i == $currentpage)
                                                $nav .= " <div class ='paging current'><a href=\"$self?currentpage=$i\">$i</a></div>";
                                        else
                                                $nav .= " <div class ='paging'><a href=\"$self?currentpage=$i\">$i</a></div> "; 
                                }
                                $q = "SELECT * FROM NEWS LIMIT $start, $pagesize";
                                $r = mysql_query($q);
                                while ($row = mysql_fetch_array($r))
                                {
                                    $id = $row["ID"];
                                    $title = $row["title"];
                                    $description = $row["description"];

                                    echo "<ul>
                                            <li class='listitem'>
                                                <div class='row'>
                                                    <h3>
                                                        <a class='user' href='modifyNews.php?id=$id'>$title</a>
                                                    </h3>
                                                </div>
                                    
                                                <div class='row definition-list'>
                                                    <span class='term'></span><span class='def'>$description</span>
                                                </div>
                                            </li>
                                        </ul>";
                                }
                                
                            ?>
                    </div>
                    <div id="paging">
                    <?php
                        
                        echo $nav;
                        echo "<p class= 'paging info'>Số trang: $numpage <br/></p>";
                    ?>
                    </div>
                </div><!--end main wrap -->
                
            </div><!--end main wrap-->
            
            <div id="footer" class="grid_12">
            </div><!--end footer wrap-->
        </div><!--end container wrap-->
    </body>
</html>
